package cn.hdu.liang;


import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;

public class Main {
    private static final int NUM = 4;
    private static InputStream[] in = new InputStream[NUM];

    public static void readImg(int i, String fileName) {
        File file = new File(fileName);
        try {
            in[i] = new FileInputStream(file);
            int n = 1024;
            byte[] buffer = new byte[n];

            while(in[i].read(buffer, 0, n) != -1) {
            }
        } catch(IOException e) {
            e.printStackTrace();
        }
    }

    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        for(int i = 0; i < NUM; i++) {
            readImg(i, "p" + i + ".iso");
        }

        for(int i = 0; i < 100000; i++) {
            compare(in[0], in[1]);
            compare(in[2], in[3]);
            //compare(in[4], in[5]);
            //compare(in[6], in[7]);
        }

        long end = System.currentTimeMillis();
        System.out.println(end - start);
    }

    private static void compare(InputStream is1, InputStream is2) {
        byte[] r1 = new byte[1024];
        byte[] r2 = new byte[1024];
        try {
            int len1 = is1.read(r1);
            int len2 = is2.read(r2);
            while(len1 == len2 && len1 != -1) {
                for(int i = 0; i < len1; i++) {
                    if(r1[i] != r2[i]) {
                        System.out.println("文件不一样");
                    }
                }
            }
        } catch(IOException e) {
            e.printStackTrace();
        }

        //System.out.println("文件一样");
    }
}